<template>
  <div class="home">
    <label>姓名</label>
    <el-input v-model="name"></el-input>
    <label>年龄</label>
    <el-input v-model="age"></el-input>
    <el-button @click.stop="handleClick">提交</el-button>
  </div>
</template>

<script>
// @ is an alias to /src
import { getUserListApi, createUserApi } from "@/service";
export default {
  name: "HomeView",
  data() {
    return {
      name: "",
      age: 0,
    };
  },
  mounted() {
    this.getUserList();
  },
  methods: {
    async getUserList() {
      try {
        const res = (await getUserListApi()).data;
        console.log(res);
      } catch (err) {
        this.$message.error(err);
      }
    },
    async handleClick() {
      const user = {
        name: this.name,
        age: this.age,
      };
      const res = (await createUserApi(user)).data;
      console.log(res);
    },
  },
};
</script>
